<?php


namespace App\Models\ProductCenter\Models;


use App\Models\ProductCenter\ProductModel;

class SkuModel extends ProductModel
{
    public $table = 'product_sku';
    public $fillable = [
        'spu_id', //varchar(64) NOT NULL COMMENT 'spu',
        'spu', //varchar(64) NOT NULL COMMENT 'spu',
        'sku', //varchar(64) NOT NULL DEFAULT '' COMMENT 'sku',
        'name',
        'image_url', //varchar(255) NOT NULL DEFAULT '' COMMENT '图片ids',
        'content', //text ,
        'stock',// int NOT NULL DEFAULT '0' COMMENT '库存',
        'price',// decimal(10,2) NOT NULL DEFAULT '0.00',
        'newest_price',// decimal(10,2) NOT NULL DEFAULT '0.00',
//        'create_time',// datetime DEFAULT NULL,
//        'update_time',// datetime DEFAULT NULL,
        'create_user',// varchar(64) NOT NULL DEFAULT '',
        'create_user_uuid',// varchar(64) NOT NULL DEFAULT '',
        'is_delete',
        'size_type',
        'sale_num',
        'status'
    ];

    public function skuInfo()
    {
        return $this->hasMany(SkuInfoModel::class, 'sku_id', 'id');
    }

    protected static function boot()
    {
        parent::boot();

        static::deleting(function($sku) {
            $sku->skuInfo()->delete();
        });
    }
}
